<template>
  <z-modal
    :width="800"
    v-bind="modalOption"
    :okText="false"
    @ok="handleOk"
    @cancel="handleCancel"
  >
    <a-spin :spinning="confirmLoading">
      <a-form-model layout="horizontal" labelAlign="right" ref="ruleForm" :label-col="labelCol" :wrapper-col="wrapperCol" :model="form" :rules="validatorRules">
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="合同名称" prop="name">
              <a-input placeholder="请输入合同名称" v-model.trim="form.name" :disabled="disableSubmit"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="客户名称" prop="customerName">
              <a-input-search v-model="form.customerName" readOnly @search="onSearchCustomer" placeholder="请输入客户名称">
                <a-button slot="enterButton">选择客户</a-button>
              </a-input-search>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="销售机会" prop="saleChance">
              <a-input placeholder="请输入销售机会" v-model.trim="form.saleChance" :disabled="disableSubmit"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="业务类型" prop="businessType">
              <z-dict-select-tag v-model="form.businessType"  dictCode="business_type" placeholder="请选择业务类型"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="合同总价" prop="money">
              <a-input-number placeholder="请输入合同总价" v-model.trim="form.money" style="width: 100%" :disabled="disableSubmit"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="签订日期" prop="orderDate">
              <a-date-picker v-model="form.orderDate"  placeholder="请选择签订日期" style="width: 100%" :disabled="disableSubmit" showTime format="YYYY-MM-DD HH:mm:ss" @change="(value,dateString) =>{ this.form.orderDate = dateString}"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="是否开票" prop="billed">
              <z-dict-select-tag v-model="form.billed"  dictCode="MB_SYSTEM_YES_NO" placeholder="请选择是否开票"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="合同负责人" prop="ownerUserId">
              <ZSelectUserByDep :multi="false" v-model="form.ownerUserId" :disabled="disableSubmit"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="所属公司" prop="company">
              <a-input placeholder="请输入所属公司" v-model.trim="form.company" :disabled="disableSubmit"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="备注" prop="remark">
              <a-input placeholder="请输入备注" v-model.trim="form.remark" :disabled="disableSubmit"/>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-spin>
    <SelectCustomerModal ref="selectModal" @ok="selectOK"></SelectCustomerModal>
  </z-modal>
</template>

<script>
import ModalFormMixin from '@/mixins/ModalFormMixin'
import ZDictSelectTag from '@/components/dict/ZDictSelectTag'
import ZSelectUserByDep from '@/components/zzbiz/ZSelectUserByDep'
import SelectCustomerModal from '@/pages/crm/customer/modules/SelectCustomerModal'

export default {
  name: "crmContractModal",
  mixins: [ModalFormMixin],
  components: {
    ZDictSelectTag,
    ZSelectUserByDep,
    SelectCustomerModal
  },
  data() {
    return {
      validatorRules: {
    name: [
      { required: true, message: '请输入合同名称!' }
    ],      },
      url: {
        add: '/contract/add',
        edit: '/contract/edit'
      },
      // 查询参数
      queryParam: {},
      selectedRowKeys: [],
      selectedRows: [],
      toggleSearchStatus: false
    }
  },
  methods: {
    addAfter() {
    },
    onSearchCustomer() {
      this.$refs.selectModal.showModal()
    },
    selectOK(rows, idstr) {
      if(!rows){
        this.form.customerId = ''
        this.form.customerName = ''
        this.form.ownerCustomer = ''
      }else{
        let row = rows[0]
        this.form.customerId = row.id
        this.form.customerName = row.customerName
        this.form.ownerCustomer = row.ownerUserId
      }
      this.form = Object.assign({},this.form)
    }
  }
}
</script>
